import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class mainWindow extends JFrame {

	static JTabbedPane jtp;

	public mainWindow() {

		// give some look'n feel to the main window
		super("Change the evil tabs!");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(500, 500);

		// setting up the menu bar
		setJMenuBar(new simpleMenu());

		// create a content pane component from JTabbedPane
		jtp = new JTabbedPane();

		jtp.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent evt) {
				// get Current tab
				int sel = jtp.getSelectedIndex();
				System.out.println("Selected tab index: " + sel);
				jtp.setComponentAt(sel, interfaceClass.box[sel]);
			}
		});

		setContentPane(jtp);
	}

	public class simpleMenu extends JMenuBar {

		private static final long serialVersionUID = 1L;
		Integer tabIndex = 0;

		// create the menu item names and define the shortcuts
		String[] fileItems = new String[] { "New Tab", "Leave Evil tab's alone" };
		char[] fileShortcuts = { 'N', 'L' };

		public simpleMenu() {

			// create a menu component
			JMenu fileMenu = new JMenu("File");

			/*
			 * add an ActionListener to the JMenuBar (this) class, the function
			 * in the listener will be performed if the user hits the "New Tabs"
			 * button in the menu bar
			 */
			ActionListener performListener = new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if (e.getActionCommand() == "New Tab") {
						interfaceClass.addOneTab(tabIndex);
						tabIndex++;
					} else if (e.getActionCommand() == "Leave Evil tab's alone") {
						System.exit(0);
					}
				}
			};

			// add the menu item together with the ActionListener to the main
			// menu
			for (int i = 0; i < fileItems.length; i++) {
				JMenuItem fileMenuItem = new JMenuItem(fileItems[i],
						fileShortcuts[i]);
				fileMenuItem.addActionListener(performListener);
				fileMenu.add(fileMenuItem);
			}

			// add the full menu to the component
			add(fileMenu);
		}
	}

	public static void main(String[] args) {
		// create a new main class component, and set it to visible
		mainWindow mw = new mainWindow();
		mw.setVisible(true);
	}
}